/**
 * 通用组件
 */
$(function () {
  //个人中心拦截
  var smsWaitTime = 80;
  var url = window.location.href;
  var pathName = window.document.location.pathname;
  var search = window.document.location.search;
  pageUrl = pathName.substring(pathName.lastIndexOf("/") + 1, pathName.length);
  saveLocalPageUrl(pageUrl + search);
  if (url.search("userCenter") != -1) {
    if (getLocalCookieUserId() == null) {
      console.warn("当前用户未登录!");
      window.location.href = "login.html";
      return;
    }
  }
  var isWeakPwd = getLocalCookieIsWeakPwd();
  if (isWeakPwd && (isWeakPwd == 'true' || isWeakPwd == true)) {
    showWeakPwdWindow();
  }
  //监控dom变化 重定位a标签 页面所有a标签在自身窗口打开
  $.getScript("https://wenhuabu-media.bj.bcebos.com/national_culture_file/pcjs/jquery-resize-1.1/jquery.ba-resize.min.js", function () {
    //加载js,成功后，并执行回调函数
    $("body").resize({
      delay: 50
    }, function () {
      $("a").attr("target", "_Self");
    });
  });
});
document.write("<script language=javascript src='js/hy.util.js'></script>");
var pageNumber = 0;
var pageSize = 10;
var myScrollLoad = null;

//隐藏分享按钮
$('.detail-text__attach-item.share').hide();


/**
 * 初始化发布栏目列表
 showTargetId： 显示目标位置   .xxx   #xxx
 params：业务参数
 callBackFunction：回调函数
 finishFunction：数据渲染完后执行，比如重新规划js组件的渲染swiper等
 */
function initCategoryList (showTargetId, params, callBackFunction, finishFunction) {
  $.ajax({
    type: "GET",
    url: urlPath + "api/category",
    data: params,
    beforeSend: function (request) {
      // request.setRequestHeader("Test", "Chenxizhang");
    },
    success: function (data) {
      if (data.code == "0") {
        if (typeof (callBackFunction) == 'function') {
          var html = callBackFunction(data);
          $(showTargetId).html(html);
        }
        if (typeof (finishFunction) == 'function') {
          finishFunction();
        }
      }
      else {
        console.log("initCategoryList:" + data.msg);
      }
    }
  });
}

/**
 * 初始化推荐列表模块
 showTargetId： 显示目标位置   .xxx   #xxx
 params：业务参数
 callBackFunction：回调函数
 finishFunction：数据渲染完后执行，比如重新规划js组件的渲染swiper等
 */
function initRecommendList (showTargetId, params, callBackFunction, finishFunction) {
  $.ajax({
    type: "GET",
    url: urlPath + "api/res/recommend",
    data: params,
    beforeSend: function (request) {
      // request.setRequestHeader("Test", "Chenxizhang");
    },
    success: function (data) {
      if (data.code == "0") {
        if (typeof (callBackFunction) == 'function') {
          var html = callBackFunction(data);
          $(showTargetId).html(html);
        }
        if (typeof (finishFunction) == 'function') {
          finishFunction();
        }
      }
      else {
        console.log("initRecommendList:" + data.msg);
      }
    }
  });
}

/**
 * 初始化发布资源列表模块
 showTargetId： 显示目标位置   .xxx   #xxx
 params：业务参数
 callBackFunction：回调函数 默认渲染函数 (定义渲染规则,数据覆盖自动完成)
 finishFunction：自定义数据渲染函数 or 数据渲染完后执行，比如重新规划js组件的渲染swiper等
 */
function initPubResList (showTargetId, params, callBackFunction, finishFunction) {
  var indexLoad;
  $.ajax({
    type: "POST",
    url: urlPath + "api/res/list",
    data: params,
    beforeSend: function (request) {
      // request.setRequestHeader("Test", "Chenxizhang");
      indexLoad = initLoad();
    },
    success: function (data) {
      if (typeof (callBackFunction) == 'function') {
        var html = callBackFunction(data);
        $(showTargetId).html(html);
        $("a").attr("target", "_Self");
      }
      if (typeof (finishFunction) == 'function') {
        finishFunction(data);
      }
      closeLoad(indexLoad);
    }
  });
}

function initLoad () {
  var indexLoad = layer.load(1, {
    shade: [0.1, '#fff'] //0.1透明度的白色背景
  });
  return indexLoad;
}

function closeLoad (indexLoad) {
  layer.close(indexLoad);
}

/**
 * 通用的ajax加载请求 
 *     该组件没有处理异常 异常自定义方法处理
 * @param ajaxParams ajax参数定义
 * @param params 业务参数
 * @param beforeFunction 请求前需要执行的函数
 * @param callBackFunction 请求成功回调函数
 * @param finishFunction 数据渲染完后执行，比如重新规划js组件的渲染swiper等
 * @returns
 */
function commonAjax (ajaxParams, params, beforeFunction, callBackFunction, finishFunction) {
  $.ajax({
    type: ajaxParams.type,
    url: urlPath + ajaxParams.url,
    async: ajaxParams.async == null ? true : false,
    headers: ajaxParams.headers,
    data: params,
    beforeSend: function (request) {
      if (typeof (beforeFunction) == 'function') {
        beforeFunction(request);
      }
    },
    success: function (data) {
      if (typeof (callBackFunction) == 'function') {
        var html = callBackFunction(data);
      }
      if (typeof (finishFunction) == 'function') {
        finishFunction();
      }
    }
  });
}

/**
 * 资源收藏/取消收藏初始化
 * pubId：资源发布id
 * targetId：收藏按钮
 * initValue：初始值
 */
function initCollectRes (pubId, targetId, initValue) {
  if (initValue != 0) {
    $(targetId).children('.info-div-icon').removeClass('icon-venueshoucang').addClass('collected');
    $(targetId).children('.info-div-num').css('color', '#B92D0A')
  }
  var praiseNum;
  $(targetId).on("click", function () {
    var userId = getLocalCookieUserId();
    if (!userId) {
      layer.open({
        style: 'font-size:23px'
        , content: "您当前尚未登录，请先登录后操作!"
        , btn: ["登录", "取消"]
        , yes: function (index) {
          location.href = "login.html"
        }
      });
      return;
    }
    $.ajax({
      type: "POST",
      url: urlPath + "api/res/collect",
      data: { pubId: pubId },
      beforeSend: function (request) {
        request.setRequestHeader("userId", userId);
      },
      success: function (data) {
        var msg = "error!";
        if (data.code == "0") {
          if (data.isCollect == 'yes') {
            $(targetId).children('.info-div-icon').removeClass('icon-venueshoucang').addClass('collected');
            $(targetId).children('.info-div-num').css('color', '#B92D0A')
            msg = "收藏成功!";
          }
          else {
            $(targetId).children('.info-div-num').css('color', '#999');
            $(targetId).children('.info-div-icon').removeClass('collected').addClass('icon-venueshoucang')
            msg = "取消收藏成功!";
          }
        }
        else {
          msg = data.msg;
        }
        layer.msg(msg);

      }
    });
  })
}

/**
 * 点赞初始化
 * pubId：资源发布id
 * targetId：点赞按钮
 * initValue：初始值
 */
function initPraiseRes (pubId, targetId, initValue, sum) {
  var number = parseInt($(targetId).children('.info-div-num').html());
  if (initValue != 0) {
    $(targetId).children('.info-div-icon').removeClass('icon-venuedianzan').addClass('parised');
    $(targetId).children('.info-div-num').css('color', '#B92D0A')
  }
  //浏览器指纹
  var userFingerprint = "";
  var params = {};
  $.getScript("https://wx.gtimg.com/wxpay_h5/fingerprint2.min.1.5.1.js", function () {  //加载js,成功后，并执行回调函数
    var fp = new Fingerprint2();
    fp.get(function (result) {
      userFingerprint = result;
    });
  });

  $(targetId).on("click", function () {
    var userId = 1;/////
    // var userId = getUserId();
    params = { pubId: pubId };
    //游客访问情况下需要传入浏览器指纹进行点赞
    params.fingerprint = userFingerprint;
    $.ajax({
      type: "POST",
      url: urlPath + "api/res/praise",
      data: params,
      beforeSend: function (request) {
        request.setRequestHeader("userId", userId);
      },
      success: function (data) {
        if (data.code == "0") {
          number = parseInt($(targetId).children('.info-div-num').html());
          $(targetId).children('.info-div-icon').removeClass('icon-venuedianzan').addClass('parised');
          $(targetId).children('.info-div-num').css('color', '#B92D0A')
          $(targetId).children('.info-div-num').html(number + 1)
        }
        else {
          layer.msg(data.msg);
          console.log("initPraiseRes:" + data.msg);
        }
      }
    });
  })
}

function encrypt (pwd) {
  var encrypt = new JSEncrypt();
  encrypt.setPublicKey(getPublic());
  return encrypt.encrypt(pwd);
}

/**
 * 投票初始化
 * targetId：投票按钮
 * initValue：初始值
 */
function initVoteRes (targetId) {
  //浏览器指纹
  var userFingerprint = "";
  var params = {};
  $.getScript("https://wx.gtimg.com/wxpay_h5/fingerprint2.min.1.5.1.js", function () {  //加载js,成功后，并执行回调函数
    var fp = new Fingerprint2();
    fp.get(function (result) {
      //result即为获取到的浏览器指纹值
      console.log("当前客户端指纹: " + result);
      userFingerprint = result;
    });
  });
  var userId = getLocalCookieUserId();
  $(targetId).on("click", function () {
    if (!userId) {
      layer.open({
        style: 'font-size:23px'
        , content: "您当前尚未登录，请先登录再进行投票!"
        , btn: ["登录", "取消"]
        , btn1: function (index) {
          location.href = "login.html"
        }
        , btn2: function (index) {
          return;
        }
      });
      return;
    }
    var ticketNumTargetId = $(this).find(".vote-ticket-num");
    var ticketNum = ticketNumTargetId.text();
    var pubIdStr = $(this).attr("pubId");
    params = { pubId: pubIdStr, mobile: getLocalCookieMobile() };
    //游客访问情况下需要传入浏览器指纹进行
    params.fingerprint = userFingerprint;
    $.ajax({
      type: "POST",
      url: urlPath + "api/res/vote",
      data: params,
      beforeSend: function (request) {
        request.setRequestHeader("userId", userId);
      },
      success: function (data) {
        if (data.code == "0") {
          ticketNumTargetId.text(Number(ticketNum) + 1);
          layer.msg("投票成功!");
          setTimeout(function () {
          }, 2000);
        }
        else {
          layer.msg(data.msg);
        }
      }
    });
  })
}

/**
 * 初始化资源评论列表
 * @param showTargetId： 显示目标位置   .xxx   #xxx
 * @param params：业务参数
 * @param callBackFunction 请求成功回调函数
 * @param finishFunction 数据渲染完后执行，比如重新规划js组件的渲染swiper等
 */
function initCommentList (showTargetId, params, callBackFunction, finishFunction) {
  // params["state"] = 2;
  $.ajax({
    type: "GET",
    url: urlPath + "api/res/comment_list",
    data: params,
    beforeSend: function (request) {
      request.setRequestHeader("userId", 1);
    },
    success: function (data) {
      if (data.code == "0") {
        if (typeof (callBackFunction) == 'function') {
          var html = callBackFunction(data);
          $(showTargetId).html(html);
        }
        if (typeof (finishFunction) == 'function') {
          finishFunction(data);
        }
      }
      else {
        console.log("initPubResList:" + data.msg);
      }
    }
  });
}

/**
 * 发送评论初始化
 * pubId：资源发布id
 * targetId：评论按钮
 * contentId 评论输入框对象
 */
function initSendCommentRes (pubIdStr, targetId, contentId, commenttag) {
  $(targetId).on("click", function () {
    var content = $(contentId).val();
    if (content == "") {
      layer.open({
        style: 'width:300px;heigth:120px;font-size:25px',
        content: "评论内容不能为空!",
        skin: 'msg'
      });
      return;
    }
    content = encodeURI(content);
    // var userId = getLocalCookieUserId();
    var userId = 1;
    var params = { pubId: pubIdStr, Content: content };
    if (!userId) {
      layer.open({
        style: 'font-size:23px'
        , content: "您当前尚未登录，请先登录后操作!"
        , btn: ["登录", "取消"]
        , yes: function (index) {
          location.href = "login.html"
        }
      });
      return;
    }
    $.ajax({
      type: "POST",
      url: urlPath + "api/user/add_comment",
      data: params,
      beforeSend: function (request) {
        request.setRequestHeader("userId", 1);
      },
      success: function (data) {
        console.log("initSendCommentRes data：");
        console.log(data);
        $(contentId).val("");
        $(commenttag).parent().find("span").text(data.commentNum)
        layer.open({
          content: data.msg,
          skin: 'msg',
        });
      }
    });
  })
}

/**
 * 获取用户信息
 * */
function getUserInfo (userId) {
  if (userId == "null" || userId == null || userId == "" || userId == undefined || userId == "undefined") {
    return;
  }
  var params = {};
  $.ajax({
    type: 'get',
    url: urlPath + 'api/user/info',
    dataType: 'json',
    data: params,
    ansy: false,
    headers: {
      userId: userId
    },
    success: function (data) {
      console.log(data);
      if (data.code == 0) {
        saveLocalCookieUserId(data.data.id, data.data.username, data.data.nickname, data.data.mobile,
          data.data.gender, data.data.birth, data.data.header, data.data.isCertification,
          data.data.realname, data.data.cardNo, data.data.createTime, data.data.isOrgan, data.data.email);
        saveLocalCookieUserInfo(data.data);
        window.location.reload();
      }
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
      console.log(XMLHttpRequest.status);
      console.log(XMLHttpRequest.readyState);
      console.log(textStatus);
    }
  });
}

/**
 * 文件上传
 * @param storeAs
 * @param file
 * @param filename
 * @param hidFilePath
 * @param hidFileName
 */
function multipartUpload (storeAs, file, filename, hidFilePath, hidFileName, callback) {
  $("#" + hidFilePath).val(storeAs);
  $("#" + hidFileName).val(filename);
  var client = new OSS.Wrapper({
    accessKeyId: 'LTAI4G92HhcJf98R6AYFtHWE',
    accessKeySecret: 'PEA6APZHLbJGYS7sA5nU2BUHMeBTfw',
    endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
    bucket: 'osshanyatemp'
  });
  client.multipartUpload(storeAs, file).then(function (result) {
    console.log(result);
    if (callback != null) {
      callback(result);
    }
  }).catch(function (err) {
    console.log(err);
  });
}

/**
 * 返回资源跳转路径
 * @param resType
 * @param pubId
 * @returns {String}
 */
function hrefResUrl (resType, pubId, collectionType, columnType) {
  var resUrl = '#';
  var tab = $.getUrlParam("tab");
  if (tab != null && tab != undefined && tab != '') {
    columnType = "tab=" + tab;  //获取当前的头部的tab  实现从哪个tab点进去的详情页还是显示当前tab
  }
  if (resType == "video") {//视频
    if (columnType == null || columnType == undefined || columnType == '') {
      columnType = "tab=resources";
    }
    resUrl = "vod-detail.html?" + columnType + "&pubId=" + pubId;
  } else if (resType == "activity") {//活动
    if (columnType == null || columnType == undefined || columnType == '') {
      columnType = "tab=eventAppointment";
    }
    resUrl = "activity-detail.html?" + columnType + "&pubId=" + pubId;
  } else if (resType == "news") {  //信息动态和公告信息
    if (collectionType != null && collectionType == 'notice') { //公告信息
      if (columnType == null || columnType == undefined || columnType == '') {
        columnType = "tab=noticeTab";
      }
      resUrl = "notice-detail.html?" + columnType + "&pubId=" + pubId;
    } else {  //信息动态
      if (columnType == null || columnType == undefined || columnType == '') {
        columnType = "tab=dynamics";
      }
      resUrl = "dynamics-detail.html?" + columnType + "&pubId=" + pubId;
    }
  } else if (resType == "venue" || resType == "place") { //场馆预定详情
    if (columnType == null || columnType == undefined || columnType == '') {
      columnType = "tab=venueBooking";
    }
    resUrl = "venueBookingDetail.html?" + columnType + "&pubId=" + pubId;
  } else if (resType == "imgtxt") { //政策法规
    if (columnType == null || columnType == undefined || columnType == '') {
      columnType = "tab=policiesregulations";
    }
    resUrl = "policies-regulations-detail.html?" + columnType + "&pubId=" + pubId;
  } else if (resType == "image") {
    if (columnType == null || columnType == undefined || columnType == '') {
      columnType = "tab=resources";
    }
    resUrl = "onlineExhibition-detail.html?" + columnType + "&pubId=" + pubId;
  } else if (resType == "live") {
    if (columnType == null || columnType == undefined || columnType == '') {
      columnType = "tab=resources";
    }
    resUrl = "livedetail.html?" + columnType + "&pubId=" + pubId;
  } else if (resType == "book") {
    if (columnType == null || columnType == undefined || columnType == '') {
      columnType = "tab=resources";
    }
    resUrl = "bookdetail.html?" + columnType + "&pubId=" + pubId;
  } else if (resType == "scenic") {
    if (columnType == null || columnType == undefined || columnType == '') {
      columnType = "tab=mapTab";
    }
    resUrl = "culturalTourism-detail.html?" + columnType + "&pubId=" + pubId;
  } else if (resType == "imgtxt") {
    if (columnType == null || columnType == undefined || columnType == '') {
      columnType = "tab=intangibleculturalheritage";
    }
    resUrl = "news-detail.html?" + columnType + "&pubId=" + pubId;
  } else if (resType == "topic") {
    if (columnType == null || columnType == undefined || columnType == '') {
      columnType = "tab=specialactivities";
    }
    resUrl = "specialactivities-detail.html?" + columnType + "&pubId=" + pubId;
  }
  return resUrl;
}
/**
 * 根据tab动态显示面包屑
 * @param resType
 * @param pubId
 * @returns {String}
 */
function tabHtml (tab) {
  var html = "";
  if (tab == "dynamics") {  //信息动态
    html = '<a href="index.html">首页</a>&gt;<a href="dynamics.html?tab=dynamics">信息动态</a>';
  } else if (tab == "eventAppointment") {
    html = '<a href="index.html">首页</a>&gt;<a href="activity.html?tab=eventAppointment">活动预约</a>';
  } else if (tab == "venueBooking") {
    html = '<a href="index.html">首页</a>&gt;<a href="venueBooking.html?tab=venueBooking">场馆预定</a>';
  } else if (tab == "mapTab") {
    html = '<a href="index.html">首页</a>&gt;<a href="culturalTourism-map.html?tab=mapTab">文旅融合</a>';
  } else if (tab == "noticeTab") {
    html = '<a href="index.html">首页</a>&gt;<a href="notice.html?tab=noticeTab">公告信息</a>';
  } else if (tab == "resources") {
    html = '<a href="index.html">首页</a>&gt;<a href="resources.html?tab=resources">数字资源</a>';
  } else if (tab == "specialactivities") {
    html = '<a href="index.html">首页</a>&gt;<a href="specialactivities.html?tab=specialactivities">专题活动</a>';
  } else if (tab == "organizationProfile") {
    html = '<a href="index.html">首页</a>&gt;<a href="organizationProfile.html?tab=organizationProfile">机构简介</a>';
  } else if (tab == "intangibleculturalheritage") {
    html = '<a href="index.html">首页</a>&gt;<a href="intangibleculturalheritage.html?tab=intangibleculturalheritage">数字非遗</a>';
  } else if (tab == "policiesregulations") {
    html = '<a href="index.html">首页</a>&gt;<a href="policies-regulations.html?tab=policiesregulations">政策法规</a>';
  } else if (tab == "index") {
    html = '<a href="index.html">首页</a>';
  } else {  //出现极端情况下  tab=null的情况下默认首页
    html = '<a href="index.html">首页</a>';
  }
  return html;
}

/**
 * 消息弹窗
 * */
function openMsg (content, time) {
  layer.open({
    content: content
    , skin: 'msg'
    , time: time
  });
}

/**
 * 获取用户编号
 * */
function getUserId () {
  var userId = getLocalCookieUserId();
  if (userId == "null" || userId == null || userId == ""
    || userId == undefined || userId == "undefined") {
    userId = 0;
  }
  return userId;
}

/**
 * 日期格式转换
 * @param str
 * @returns {*}
 */
function formatTime (str) {
  if (!str) {
    return "";
  }
  str = str.replace("-", "/").replace("-", "/");
  var date = new Date(str);
  return date.getFullYear() + "-" + dateValue(date.getMonth() + 1) + "-" + dateValue(date.getDate());
}

function dateValue (value) {
  return (value + "").length == 1 ? ("0" + value) : value;
}

/**
 * 设置用户ID到缓存 参数:userId,localMkUserId,openId,userMobile,userName,cardStatusDic,userTypeDic
 */
function saveLocalCookieUserId (userId, username, nickname, mobile, gender, birth, header, isCertification, realname, cardNo, createTime, isOrgan, email) {
  Cookies.remove('localUserId'); // 删除 cookie
  Cookies.remove('localUsername'); // 删除 cookie
  Cookies.remove('localNickname'); // 删除 cookie
  Cookies.remove('localMobile'); // 删除 cookie
  Cookies.remove('localGender'); // 删除 cookie
  Cookies.remove('localBirth'); // 删除 cookie
  Cookies.remove('localHeader'); // 删除 cookie
  Cookies.remove('localIsCertification'); // 删除 cookie
  Cookies.remove('localRealname'); // 删除 cookie
  Cookies.remove('localCardNo'); // 删除 cookie
  Cookies.remove('localCreateTime'); // 删除 cookie
  Cookies.remove('localIsOrgan'); // 删除 cookie
  Cookies.remove('localEmail'); // 删除 cookie

  Cookies.set('localUserId', userId); // 保存Cookie
  Cookies.set('localUsername', encodeURI(username)); // 保存Cookie
  Cookies.set('localNickname', encodeURI(nickname)); // 保存Cookie
  Cookies.set('localMobile', mobile); // 保存Cookie
  Cookies.set('localGender', gender); // 保存Cookie
  Cookies.set('localBirth', birth); // 保存Cookie
  Cookies.set('localHeader', header); // 保存Cookie
  Cookies.set('localIsCertification', isCertification); // 保存Cookie
  Cookies.set('localRealname', encodeURI(realname)); // 保存Cookie
  Cookies.set('localCardNo', cardNo); // 保存Cookie
  Cookies.set('localCreateTime', createTime); // 保存Cookie
  Cookies.set('localIsOrgan', isOrgan); // 保存Cookie
  Cookies.set('localEmail', email); // 保存Cookie
};

/**
 * 设置用户ID到缓存 参数:userId,localMkUserId,openId,userMobile,userName,localCardStatusDic
 */
function removeLocalCookieUserId () {
  Cookies.remove('localUserId');
  Cookies.remove('localUsername');
  Cookies.remove('localNickname');
  Cookies.remove('localMobile');
  Cookies.remove('localGender');
  Cookies.remove('localBirth');
  Cookies.remove('localHeader');
  Cookies.remove('localIsCertification');
  Cookies.remove('localRealname');
  Cookies.remove('localCardNo');
  Cookies.remove('localCreateTime');
  Cookies.remove('localIsOrgan');
  Cookies.remove('localEmail');
  removeLocalCookieIsWeakPwd();
};

//从缓存获取用户ID
function getLocalCookieUserId () {
  var localUserId = Cookies.get('localUserId');
  return localUserId;
};

//从缓存获取账号
function getLocalCookieUsername () {
  var localUsername = decodeURI(Cookies.get('localUsername'));
  return localUsername;
};

//从缓存获取真实姓名
function getLocalCookieNickname () {
  var localNickname = Cookies.get('localNickname');
  return localNickname;
};

//从缓存获取用户手机号码
function getLocalCookieMobile () {
  var localMobile = Cookies.get('localMobile');
  return localMobile;
};

//从缓存获取用户性别
function getLocalCookieGender () {
  var localGender = Cookies.get('localGender');
  return localGender;
};

//从缓存获取用户生日
function getLocalCookieBirth () {
  var localBirth = Cookies.get('localBirth');
  return localBirth;
};

//从缓存获取用户头像
function getLocalCookieHeader () {
  var localHeader = Cookies.get('localHeader');
  return localHeader;
};

//从缓存获取用户类型
function getLocalCookieIsOrgan () {
  var localHeader = Cookies.get('localIsOrgan');
  return localHeader;
};

//从缓存获取用户是否认证
function getLocalCookieIsCertification () {
  var localIsCertification = Cookies.get('localIsCertification');
  return localIsCertification;
};

//从缓存获取用户真实姓名
function getLocalCookieRealname () {
  var localRealname = Cookies.get('localRealname');
  return localRealname;
};

//从缓存获取用户卡号
function getLocalCookieCardNo () {
  var localCardNo = Cookies.get('localCardNo');
  return localCardNo;
};

//从缓存获取用户创建时间
function getLocalCookieCreateTime () {
  var localCreateTime = Cookies.get('localCreateTime');
  return localCreateTime;
};

//从缓存获取用户类型
function getLocalCookieIsOrgan () {
  var localIsOrgan = Cookies.get('localIsOrgan');
  return localIsOrgan;
};

//从缓存获取Email
function getLocalCookieEmail () {
  var localEmail = Cookies.get('localEmail');
  return localEmail;
};

//*************************************************************************************

/**
 * 设置用户信息到缓存 参数:userInfo
 */
function saveLocalCookieUserInfo (userInfo) {
  Cookies.remove('localUserInfo'); // 删除 cookie
  Cookies.set('localUserInfo', userInfo); // 保存Cookie
};

/**
 * 设置用户信息到缓存
 */
function removeLocalCookieUserInfo () {
  Cookies.remove('localUserInfo'); // 删除 cookie
};

/**
 * 从缓存获取用户ID
 */
function getLocalCookieUserInfo () {
  var userInfo = Cookies.get('localUserInfo');
  return userInfo;
};

/**
 * 设置关键字到缓存 参数:keywords
 */
function saveLocalCookieKeywords (keywords) {
  Cookies.remove('localKeywords'); // 删除 cookie
  Cookies.set('localKeywords', keywords); // 保存Cookie
};

/**
 * 设置关键字到缓存
 */
function removeLocalCookieKeywords () {
  Cookies.remove('localKeywords'); // 删除 cookie
};

/**
 * 从缓存获取关键字
 */
function getLocalCookieKeywords () {
  var keywords = Cookies.get('localKeywords');
  return keywords;
};

/**
 * 设置选择地区到缓存 参数:address
 */
function saveLocalCookieAddressId (address) {
  Cookies.remove('localAddressId'); // 删除 cookie
  Cookies.set('localAddressId', address); // 保存Cookie
};

/**
 * 设置选择地区到缓存
 */
function removeLocalCookieAddressId () {
  Cookies.remove('localAddressId'); // 删除 cookie
};

/**
 * 从缓存获取选择地区
 */
function getLocalCookieAddressId () {
  var address = Cookies.get('localAddressId');
  return address;
};

/**
 * 设置选择地区到缓存 参数:address
 */
function saveLocalCookieAddressName (address) {
  Cookies.remove('localAddressName'); // 删除 cookie
  Cookies.set('localAddressName', encodeURI(address)); // 保存Cookie
};

/**
 * 设置选择地区到缓存
 */
function removeLocalCookieAddressName () {
  Cookies.remove('localAddressName'); // 删除 cookie
};

/**
 * 从缓存获取选择地区
 */
function getLocalCookieAddressName () {
  var address = Cookies.get('localAddressName');
  return address;
};

function saveLocalCookieIsWeakPwd (isWeakPwd) {
  Cookies.remove('isWeakPwd');
  Cookies.set('isWeakPwd', isWeakPwd);
};

function saveLocalPageUrl (pageUrl) {
  if (pageUrl.indexOf('login.html') < 0 && pageUrl.indexOf('updatepwd.html') < 0) {
    Cookies.remove('pageUrl');
    Cookies.set('pageUrl', pageUrl);
  }

};
function getLocalPageUrl () {
  return Cookies.get('pageUrl');
};

function getLocalCookieIsWeakPwd () {
  var isWeakPwd = Cookies.get('isWeakPwd');
  return isWeakPwd;
};

function removeLocalCookieIsWeakPwd () {
  Cookies.remove('isWeakPwd');
};

function pageRedirect () {
  var pageUrl = getLocalPageUrl();
  if (pageUrl && pageUrl.indexOf('login.html') < 0 && pageUrl.indexOf('updatepwd.html') < 0) {
    window.location.href = pageUrl;
  } else {
    window.location.href = "index.html";
  }
}

/**
 * 时间戳转换
 * @param m
 * @returns {string}
 */
function add0 (m) {
  return m < 10 ? '0' + m : m
}
function formatToDateTime (datetime) {
  var time = new Date(datetime);
  var y = time.getFullYear();
  var m = time.getMonth() + 1;
  var d = time.getDate();
  var h = time.getHours();
  var mm = time.getMinutes();
  var s = time.getSeconds();
  return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
}

/**
 * 获得当前年-月-日
 * @returns {string}
 */
function getNowFormatDate () {
  var date = new Date();
  var seperator1 = "-";
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  var currentdate = year + seperator1 + month + seperator1 + strDate;
  return currentdate;
}


function formatToDate (datetime) {
  var time = new Date(datetime);
  var y = time.getFullYear();
  var m = time.getMonth() + 1;
  var d = time.getDate();
  return y + '-' + add0(m) + '-' + add0(d);
}
/*
 * 跳转pdf预览页面
 */
function pathFileUrl (fileUrl) {
  return 'https://osshanyadev.oss-cn-hangzhou.aliyuncs.com/national/pdfjs/web/viewer.html?file=' + fileUrl;
}

function getPublic () {
  return "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCu5oCYtRschaI6NUMzB/H83M4yUQtp14eORDLkINf3lDLTf6nXow9Uk0XiUQ+tyaYa/5rWgGYs5JIrA+CoZ0YOPsRJ+Ok7GNTOxtiDNf73yLuY39a3YRGP+TdUvDZY7vAsvT9EJ8ASQUD35Z4s77AX1d3ZDqeHMD4tVWA5DfmRyQIDAQAB";
}

function showWeakPwdWindow () {
  var r = window.location.href;
  if (r.indexOf("user-center-settings.html") < 0) {
    layer.open({
      type: 1,
      title: false,
      shade: 0.6,
      closeBtn: 0,
      shadeClose: false,
      scrollbar: false,
      skin: 'layer-password',
      content: '<div class="win-container">' +
        '<div class="title"></div>' +
        '<div class="win-content"><img src="img/layer-password-ico.png" alt=""/><br/>' +
        '<p>账户安全校验已升级，您的密码存在风险！请前往修改！</p>' +
        '</div>' +
        '<div class="win-btn">' +
        '<a href="user-center-settings.html" class="leave_modif_btn">前往修改</a>' +
        '</div>' +
        '</div>',
      success: function () {
      }
    });
  }
}
/**
 * 暂无数据
 * **/
function getNoDataHtml () {
  var html = '';
  html += '<div class="module-container data-none-container" style="margin: 0 auto">';
  html += '<img src="image/data-none.png" alt="">';
  html += '</div>';
  return html;
}

/**
 * 路径参数获取
 */
(function ($) {
  $.getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
      return decodeURI(r[2]);
    }
    return null;
  }
})(jQuery);




